﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Configuration;
using System.Security.Cryptography;
using System.Text;

public partial class login : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void Login_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            OTOWeb.DataOut dto = new OTOWeb.DataOut();
           
            if (txtUserName.Text.Trim() != "" && txtPassWord.Text.Trim() != "")
            {
                bool ck = dto.Checklogin(txtUserName.Text, txtPassWord.Text);
                if (ck)
                {

                    Session["uname"] = txtUserName.Text;
                    //DataTable data =  _a.GetPermission(txtUserName.Text, txtPassWord.Text)
                    Response.Redirect("QuanLy.aspx");

                }
                else
                {

                    txtUserName.Text = "";
                    txtPassWord.Text = "";
                    Label3.Text = "Tên tài khoản hoặc mật khẩu không chính xác";

                }
            }
        } 
    }
    public string EncodePassword(string originalPassword)
    {
        //Declarations
        Byte[] originalBytes;
        Byte[] encodedBytes;
        MD5 md5;

        //Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password)
        md5 = new MD5CryptoServiceProvider();
        originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
        encodedBytes = md5.ComputeHash(originalBytes);

        //Convert encoded bytes back to a 'readable' string
        return BitConverter.ToString(encodedBytes).Replace("-", string.Empty);
    }
}